import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-11-18
 * Time: 21:20
 */
public class test_1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            char[] chars = in.next().toCharArray();
            int n = chars.length;
            int ret = -1;
            for (int i = 0; i < chars.length; i++) {
                if (i + 1 < n && chars[i] == chars[i + 1]) {
                    ret = 2;
                    break;
                }
                if (i + 2 < n && chars[i] == chars[i + 2]) {
                    ret = 3;
                }
            }
            System.out.println(ret);
        }
    }
}
